﻿function AutoCompleteBox(txtnameid, txtvalueid, type) {
    $("#" + txtnameid).css({"background": "#74E4F1"},{"height":"20px"});
    $("#" + txtnameid).autocomplete({
        source: function(request, response) {
            $.ajax({
                url: "../../UserControl/SuggestBox/JquerySuggest.ashx",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                data: {
                    contype: type,
                    term: request.term
                },
                //success: function(data) { response(data); }
                success: function(data) {
                    response($.map(data, function(item) {
                        return { label: item._Name, value: item._Name, id: item._ID }
                    }))
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert("input");
                                        //alert(XMLHttpRequest.status);
                                        //alert(XMLHttpRequest.responseText);
                                        //alert(XMLHttpRequest);
                                        //alert(textStatus);
                                        //alert(errorThrown);
                    alert("查询错误！");
                }
            });
        },
        minLength: 1,
        select: function(event, ui) {
            $("#" + txtvalueid).val(ui.item.id);            
        },
        open: function() {
            $(this).removeClass("ui-corner-all").addClass("ui-corner-top");
        },
        close: function() {
            $(this).removeClass("ui-corner-top").addClass("ui-corner-all");
            var str = txtnameid.toString().split("_");
            var ctrID = "";
            for (var i = 0; i < str.length; i++) {
                if (i != (str.length - 1)) {
                    ctrID += str[i] + "_";
                }
            }
            $("#" + ctrID + "btnHID").click();
            $("#" + txtvalueid).change();
        }
    });

    $("#" + txtnameid).change(function() { $("#" + txtvalueid).val(''); });
}


function AutoCompleteBoxPlates(txtnameid, txtvalueid, txtThickness, txtOutlineSize, type) {
    $("#" + txtnameid).css({ "background": "#74E4F1" }, { "height": "20px" });
    $("#" + txtnameid).autocomplete({
        source: function (request, response) {
            $.ajax({
                url: "../../UserControl/SuggestBox/JquerySuggest.ashx",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                data: {
                    contype: type,
                    term: request.term
                },
                //success: function(data) { response(data); }
                success: function (data) {
                    response($.map(data, function (item) {
                        return { label: item._Name, value: item._Name, id: item._ID, Thick: item._Thick, Size: item._Size }
                    }))
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    //                    alert(XMLHttpRequest.status);
                    //                    alert(XMLHttpRequest.responseText);
                    //                    alert(XMLHttpRequest);
                    //                    alert(textStatus);
                    //                    alert(errorThrown);
                    alert("查询错误！");
                }
            });
        },
        minLength: 1,
        select: function (event, ui) {
            $("#" + txtvalueid).val(ui.item.id);
            $("#" + txtThickness).val(ui.item.Thick);
            $("#" + txtOutlineSize).val(ui.item.Size);
        },
        open: function () {
            $(this).removeClass("ui-corner-all").addClass("ui-corner-top");
        },
        close: function () {
            $(this).removeClass("ui-corner-top").addClass("ui-corner-all");
            var str = txtnameid.toString().split("_");
            var ctrID = "";
            for (var i = 0; i < str.length; i++) {
                if (i != (str.length - 1)) {
                    ctrID += str[i] + "_";
                }
            }
            $("#" + ctrID + "btnHID").click();
            $("#" + txtvalueid).change();
            $("#" + txtThickness).change();
            $("#" + txtOutlineSize).change();
        }
    });

    $("#" + txtnameid).change(function () { $("#" + txtvalueid).val('');$("#" + txtThickness).val('');$("#" + txtOutlineSize).val(''); });
}

function AutoCompleteBoxRequisit(txtnameid, txtvalueid, type) {
    $("#" + txtnameid).css({ "background": "#74E4F1" }, { "height": "20px" });
    $("#" + txtnameid).autocomplete({
        source: function (request, response) {
            $.ajax({
                url: "../../UserControl/SuggestBox/JquerySuggest.ashx",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                data: {
                    contype: type,
                    term: request.term
                },
                //success: function(data) { response(data); }
                success: function (data) {
                    response($.map(data, function (item) {
                        return { label: item._Name, value: item._Name, id: item._ID }
                    }))
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                        alert(XMLHttpRequest.status);
                                        alert(XMLHttpRequest.responseText);
                                        alert(XMLHttpRequest);
                                        alert(textStatus);
                                        alert(errorThrown);
                    alert("查询错误！");
                }
            });
        },
        minLength: 1,
        select: function (event, ui) {
            $("#" + txtvalueid).val(ui.item.id);
        },
        open: function () {
            $(this).removeClass("ui-corner-all").addClass("ui-corner-top");
        },
        close: function () {
            $(this).removeClass("ui-corner-top").addClass("ui-corner-all");
        }
    });

    $("#" + txtnameid).change(function () { $("#" + txtvalueid).val(''); });
}